<!--封装上传组件-->
<template>
    <section>
        <form>
            <input type="file" ref="myFile"  v-show="false" @change="getFile($event)" :accept="accept"/>
            <input type="reset" ref="myReset" v-show="false"/>
        </form>
        <el-button class="el-icon-upload" @click="selectFile" type="info">{{buttonName}}</el-button>
    </section>
</template>

<script>

    export default{
        data(){
            return {

            }
        },
        props: ['buttonName','accept'],
        methods: {
            /**
             *文件选取完的回调
             * @param event
             */
            getFile(event){
                if (event.target.files.length != 0) {
                    let file = event.target.files[0];
                    this.$emit('selectedFile', file)
                }
            },
            selectFile(){
                this.$refs.myReset.click();//点击重置按钮 先重置表单数据

                this.$refs.myFile.click();//点击真正的上传按钮
            }
        }
    }
</script>